package top.chengdongqing.mishop.media.banner

import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Service
import top.chengdongqing.mishop.enums.BannerType
import top.chengdongqing.mishop.repositories.BannerRepository

@Service
class BannerService(
    private val bannerRepository: BannerRepository
) {

    @Cacheable(value = ["media:banners"], key = "#type")
    fun findBanners(type: BannerType): List<BannerVO> {
        val banners = bannerRepository.findAllByTypeAndEnabledTrueOrderBySortNo(type)
        return BannerVO.of(banners)
    }
}